package cn.ucuser.music.directive;

import cn.ucuser.music.model.JpressAddonMusic;
import cn.ucuser.music.service.JpressAddonMusicService;
import com.jfinal.aop.Inject;
import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;
import io.jboot.web.directive.annotation.JFinalDirective;
import io.jboot.web.directive.base.JbootDirectiveBase;

@JFinalDirective("musicDirective")
public class MusicDirective extends JbootDirectiveBase {

    @Inject
    private JpressAddonMusicService service;

    @Override
    public void onRender(Env env, Scope scope, Writer writer) {
        JpressAddonMusic byId = service.findById(1);
        Object url = getPara("url", scope);
        String html ="<link rel=\"stylesheet\" href=\""+url+"/build/css/poi.css\"><div id=\"poi-play-bar\" class=\"poi-play-bar poi-c\">\n" +
                "    <div class=\"poi-control\">\n" +
                "        <div class=\"rewind\"><i class=\"poifont\">&#xe60e;</i></div>\n" +
                "        <div class=\"poiplay playing loadMusic\"><i class=\"poifont\">&#xe60c;</i></div>\n" +
                "        <div class=\"fastforward\"><i class=\"poifont\">&#xe60f;</i></div>\n" +
                "        <div class=\"poi-progress\">\n" +
                "            <div class=\"poi-sider\">\n" +
                "                <div class=\"poi-loaded\"></div>\n" +
                "                <div class=\"poi-pace\"></div>\n" +
                "            </div>\n" +
                "            <span class=\"poi-tag poi-song-title\">正在获取，请稍候...</span>\n" +
                "        </div>\n" +
                "        <div class=\"poi-timer\">00:00/00:00</div>\n" +
                "        <div class=\"shuffle-play\"><i class=\"poifont shuffle\">&#xe604;</i></div>\n" +
                "        <div class=\"poi-volume\"><i class=\"poifont mute\">&#xe605;</i></div>\n" +
                "        <div class=\"poi-open-list\"><i class=\"poifont\">&#xe609;</i></div>\n" +
                "    </div>\n" +
                "    <div id=\"open-poi-player\"><i class=\"poifont\">&#xe608;</i></div><!-- Open Bar -->\n" +
                "</div>\n" +
                "<div id=\"poi-music-list\" class=\"poi-music-list-c\">\n" +
                "    <div class=\"poi-list-title\">\n" +
                "        <span class=\"poi-album-tiele\"></span>\n" +
                "        <span class=\"poi-album-tags\"></span>\n" +
                "        <span class=\"poi-list-close\" style=\"display: block\"><i class=\"poifont\">&#xe60b;</i></span>\n" +
                "    </div>\n" +
                "    <div id=\"poi-playlist\">\n" +
                "        <ul>\n" +
                "        </ul>\n" +
                "    </div>\n" +
                "    <div id=\"poi-lrc\" class=\"poi-lrc-c\">\n" +
                "        <div id=\"lrcWrap\" class=\"lrc-wrap lrc-wrap-open\">\n" +
                "            <div id=\"lrcBox\" class=\"lrc-box\">\n" +
                "                <div id=\"lrc_2\">\n" +
                "                </div>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "        <div id=\"scripylrc\">\n" +
                "            <p>\n" +
                "            </p>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "    <div id=\"poi-song-cover\"><img src=\""+url+"/build/images/cover.jpg\"></div>\n" +
                "    <div class=\"czui czui-c\"></div>\n" +
                "</div>\n" +
                "<div id=\"music-json\" class=\"music-json\" style=\"display: none;\">\n" +
                "    <script type=\"text/javascript\">\n" +
                "        var playlist ="+byId.getJson() +
                "            ,mautoplay = \"\",\n" +
                "            mshuffle = \"\",\n" +
                "            boxsearch = false,\n" +
                "            geturl = \"/\";\n" +
                "    </script>\n" +
                "</div>\n" +
                "<script src=\""+url+"/build/js/player-base.min.js\"></script>\n" +
                "<script src=\""+url+"/build/js/poi.min.js\"></script>";
        scope.setLocal("musicHtml", html);
        renderBody(env, scope, writer);
    }
    @Override
    public boolean hasEnd() {
        return true;
    }
}
